package com.study.泛型;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * 利用反射，绕过编译器去调用List的 add 方法
 */
public class ToolTest {

	public static void main(String[] args) {
		List<Integer> ls = new ArrayList<>();
		ls.add(2357);
//		ls.add("text");
		try {
			Method method = ls.getClass().getDeclaredMethod("add",Object.class);
			method.invoke(ls,"test");
			method.invoke(ls,42.9f);
		} catch (Exception e) {
			e.printStackTrace();
		}

		for ( Object o: ls){
			System.out.println(o + "\t||\t" + o.getClass());
		}


	}

}

